﻿//原型功能补充及兼容性修正
//css函数的selection函数需要tools.js模块，animate函数需要Animate.js模块

if (!window.addEventListener) {//若window对象没有标准的事件侦听函数，用ie事件侦听函数模拟实现标准事件侦听
    window.addEventListener = function (eventString, eventHandler) {
        window.attachEvent("on" + eventString, eventHandler);
    };

    window.removeEventListener = function (eventString, eventHandler) {
        window.detachEvent("on" + eventString, eventHandler);
    };
}

window.getScrollOffset = function () {//返回滚动条偏移量,兼容修正
    var w = this;

    if (w.pageXOffset != null) return { x: w.pageXOffset, y: w.pageYOffset };

    //兼容ie8及以下
    var d = w.document;
    if (d.compatMode === "CSS1Compat") return { x: d.documentElement.scrollLeft, y: d.documentElement.scrollTop };

    //怪异模式
    return { x: d.body.scrollLeft, y: d.body.scrollTop };
};

window.getViewportSize = function () {//返回视口大小
    var w = this;
    if (w.innerWidth != null) return { w: w.innerWidth, h: w.innerHeight };

    //兼容ie8及以下
    var d = w.document;
    if (document.compatMode === "CSS1Compat") {
        return { w: d.documentElement.clientWidth, h: d.documentElement.clientHeight };
    }

    //怪异模式
    return { w: d.body.clientWidth, h: d.body.clientHeight };

};



try{
    Element.prototype;
}catch(e){
    window.Element = function () { };
    window.HTMLInputElement = function () { };

    window.HTMLSelectElement = function () { };
    window.HTMLButtonElement = function () { };
    window.HTMLTextAreaElement = function () { };
    window.HTMLFormElement = function () { };

    (function () {
        var setC = function (el) {
            if (el.css) {
                return;
            }
            for (var i in Element.prototype) {
                el[i] = Element.prototype[i];
            }

            var pro = null;
            switch (el.tagName.toLowerCase()) {
                case "input":
                    pro = HTMLInputElement.prototype;
                    break;
                case "select":
                    pro = HTMLSelectElement.prototype;
                    break;
                case "button":
                    pro = HTMLButtonElement.prototype;
                    break;
                case "textarea":
                    pro = HTMLTextAreaElement.prototype;
                    break;
                case "form":
                    pro = HTMLFormElement.prototype;
                    break;
                default:
                    break;
            }

            if (pro) {
                for(i in pro){
                    el[i] = pro[i];
                }
            }
        };

        wkh.tools._ie67 = function (dom) {
            if (!dom) {
                setC(document.body);
                Array.prototype.forEach.call(wkh.select("body *"), setC);
            } else {
                setC(dom);
            }
        };

        var create = document.createElement;
        document.createElement = function (tagName) {
            if (!tagName) {
                return;
            }
            tagName = tagName.toLowerCase();
            var dom = create(tagName);

            //for (var i in Element.prototype) {
            //    dom[i] = Element.prototype[i];
            //}
            //if (tagName === "input" || tagName === "textarea") {
            //    for (var i in HTMLInputElement.prototype) {
            //        dom[i] = HTMLInputElement.prototype[i];
            //    }
            //}

            setC(dom);

            return dom;
        };
    }());
}//ie67兼容性

if (!document.getElementsByClassName) {//兼容修正ie8 getElementsByClassName方法
    //HTMLDocument.prototype
    document.getElementsByClassName = Element.prototype.getElementsByClassName = function (className) {
        var node = this;
        var classList = className.trim();
        if (this.querySelectorAll) {
            classList = classList.replace(/[\s]+/g, ".");
            try {
                return this.querySelectorAll("." + classList);
            } catch (e) {
                //若出错，跳出进行下一步的执行;
            }
        }
        classList = classList.replace(/[\s]+/g, " ").split(" ");
        var classListLength = classList.length;
        for (var i = 0, j = classListLength; i < j; ++i) {//替换匹配className的正则表达
            classList[i] = new RegExp("(^|\\s)" + classList[i].replace(/\-/g, "\\-") + "(\\s|$)");
        }
        var elements = node.getElementsByTagName("*");//得到节点下所有节点
        var result = [];
        for (var i = 0, j = elements.length, k = 0; i < j; ++i) {
            var element = elements[i];
            while (classList[k++].test(element.className)) {
                if (k === classListLength) {
                    result[result.length] = element;
                    break;
                }
            }
            k = 0;
        }
        return result;
    };
}

Element.prototype.getComputedStyle = function (pseudoEle) {//获得元素计算css属性
    var pe = pseudoEle || "";

    var obj = this;
    if (window.getComputedStyle) return window.getComputedStyle(obj, pe);
    return this.currentStyle;
};

Element.prototype.realBoxSize = function () {//返回元素实际长宽
    return wkh.tools.realBoxSize(this);
};

Element.prototype.getBoxSize = function (boxSizing) {//返回盒子尺寸信息,参数值为 content-box,border-box,padding-box,margin-box
    this.getBoundingClientRect();
    var boxE = this.getBoundingClientRect();

    var scroll = window.getScrollOffset();

    var box = {
        top: boxE.top + scroll.y,
        bottom: boxE.bottom + scroll.y,
        left: boxE.left + scroll.x,
        right: boxE.right + scroll.x,
        width: boxE.width || boxE.right - boxE.left,
        height: boxE.height || boxE.bottom - boxE.top
    };

    function getBorderWidth(css) {
        if (!window.getComputedStyle) {
            var value = style[css];
            if (style[css.slice(0, -5) + "Style"] === "none") {
                return 0;
            } else {
                switch (value) {
                    case "thin": return 1;
                    case "medium": return 3;
                    case "thick": return 5;
                    default: return parseFloat(style[css]);
                }
            }
        } else {
            return parseFloat(style[css]);
        }
    }

    var style = this.getComputedStyle();
    boxSizing = boxSizing || "border-box";
    switch (boxSizing) {
        case "content-box":
            box.width = box.width - getBorderWidth("borderLeftWidth") - getBorderWidth("borderRightWidth") - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);
            box.height = box.height - getBorderWidth("borderBottomWidth") - getBorderWidth("borderTopWidth") - parseFloat(style.paddingBottom) - parseFloat(style.paddingTop);
            break;
        case "padding-box":
            box.width = box.width - getBorderWidth("borderLeftWidth") - getBorderWidth("borderRightWidth");
            box.height = box.height - getBorderWidth("borderBottomWidth") - getBorderWidth("borderTopWidth");
            break;
        case "border-box":
            break;
        case "margin-box":
            box.width = box.width + parseFloat(style.marginLeft) + parseFloat(style.marginRight);
            box.height = box.height + parseFloat(style.marginBottom) + parseFloat(style.marginTop);
            break;
        default:
            break;
    }

    return box;
};

Element.prototype.css = (function () {

    var thisObject = null;

    function getCssValue(cssRules) {
        cssRules = wkh.tools.preFixCss(cssRules) || cssRules;//如果无法得到浏览器相关cssRules，使用原值

        var computedStyle = thisObject.getComputedStyle();
        var computedValue = computedStyle[cssRules];//先得到计算值,兼容不同浏览器

        if (!window.getComputedStyle && cssRules.search("[cC]olor") !== -1) {//兼容ie8颜色返回一个rgb或rgba标准值
            var computedValue = wkh.tools.analyticColor(computedValue);
            if (computedValue.length === 3) return "rgb(" + computedValue.join(", ") + ")";
            else {
                if (!window.getComputedStyle && computedValue[0] === 0 && computedValue[1] === 0 && computedValue[2] === 0 && computedValue[3] === 0) {//ie8反回transparent
                    return "transparent";
                }
                return "rgba(" + computedValue.join(", ") + ")";
            }
        }

        if (cssRules === "width") {//兼容在某些浏览器设置boxSizing返回值
            return thisObject.getBoxSize(computedStyle.boxSizing).width + "px";
        }

        if (cssRules === "height") {
            return thisObject.getBoxSize(computedStyle.boxSizing).height + "px";
        }

        if (!window.getComputedStyle) {
            var reg;
            if (reg = cssRules.match(/^border(Left|Right|Top|Bottom)Width$/)) {
                if (computedStyle["border" + reg[1] + "Style"] === "none") {
                    return "0px";
                } else {
                    switch (computedValue) {
                        case "thin": return "1px";
                        case "medium": return "3px";
                        case "thick": return "5px";
                        default: return computedValue;
                    }
                }
            }
        }

        if (cssRules === "opacity") {
            if ("opacity" in document.body.style) { return computedValue; }
            else {
                computedValue = /alpha\s*\(\s*(?:[\w=]+\s+)*opacity\s*=\s*([0-9]{1,3})\s*(?:[\w=]+\s+)*\)/.exec(computedStyle.filter.trim().toLowerCase());
                return computedValue ? computedValue[1] / 100 + "" : "1";
            }
        }

        if (computedValue === "auto") {//若为auto，则还要具体计算
            switch (cssRules) {
                case "left":
                    if (computedStyle.position === "relative") {
                        return computedStyle.right === "auto" ? "0px" : -parseFloat(computedStyle.right) + "px";
                    } else {
                        return thisObject.offsetLeft + "px";
                    }
                    break;
                case "top":
                    if (computedStyle.position === "relative") {
                        return computedStyle.bottom === "auto" ? "0px" : -parseFloat(computedStyle.bottom) + "px";
                    } else {
                        return thisObject.offsetTop + "px";
                    }
                    break;
                case "right":
                    if (computedStyle.position === "relative") {
                        return computedStyle.left === "auto" ? "0px" : -parseFloat(computedStyle.left) + "px";
                    } else {
                        return "0px";
                    }
                    break;
                case "bottom":
                    if (computedStyle.position === "relative") {
                        return computedStyle.top === "auto" ? "0px" : -parseFloat(computedStyle.top) + "px";
                    } else {
                        return "0px";//这两个还未完善
                    }
                    break;
            }
        }

        return computedValue;
    }

    function mergeCss(arr) {//合并css值，如padding:10px 10px 10px 10px合成10px，参数为数组
        if (arr[3] === arr[1]) arr.pop();
        else return arr;

        if (arr[2] === arr[0]) arr.pop();
        else return arr;

        if (arr[1] === arr[0]) arr.pop();
        else return arr;

        return arr;
    }

    function setCss(cssRule, value) {
        if (cssRule === "opacity") {//如果为opacity,特殊处理
            if (value === "") {
                value = 1;
            } else {
                value = parseFloat(value);
            }

            if ("opacity" in thisObject.style) {
                thisObject.style.opacity = value;
            } else {
                thisObject.style.filter = "alpha(opacity=" + Math.round(value * 100) + ")";
            }
        } else {
            cssRule = wkh.tools.preFixCss(cssRule) || cssRule;
            try{
                thisObject.style[cssRule] = value;
            }catch(e){
            }
        
        }
    }

    return function (cssRules, value) {//返回的函数
        if (!cssRules) {
            return;
        }
        thisObject = this;

        if (Object.classof(cssRules) === "Object") {
            for (var n in cssRules) {
                setCss(n, cssRules[n]);
            }
        } else if (value != null) {//赋值
            setCss(cssRules, value);
        } else {//返回值
            switch (cssRules) {
                case "font":
                    return [getCssValue("fontStyle"), getCssValue("fontVariant"), getCssValue("fontWeight"), getCssValue("fontSize"), getCssValue("fontFamily")].join(" ");
                case "padding": case "margin":
                    return mergeCss([getCssValue(cssRules + "Top"), getCssValue(cssRules + "Right"), getCssValue(cssRules + "Bottom"), getCssValue(cssRules + "Left")]).join(" ");
                case "outline": case "borderTop": case "borderRight": case "borderBottom": case "borderLeft":
                    return [getCssValue(cssRules + "Color"), getCssValue(cssRules + "Width"), getCssValue(cssRules + "Style")].join(" ");
                case "borderWidth": case "borderColor": case "borderStyle":
                    return mergeCss([getCssValue("borderTop" + cssRules.slice(6)), getCssValue("borderRight" + cssRules.slice(6)), getCssValue("borderBottom" + cssRules.slice(6)), getCssValue("borderLeft" + cssRules.slice(6))]).join(" ");
                case "border":
                    return this.css("borderTop");
                case "borderRadius":
                    return mergeCss([getCssValue("borderTopLeftRadius"), getCssValue("borderTopRightRadius"), getCssValue("borderBottomRightRadius"), getCssValue("borderBottomLeftRadius")]).join(" ");
                case "background":
                    return [getCssValue("backgroundColor"), getCssValue("backgroundImage"), getCssValue("backgroundRepeat"), getCssValue("backgroundAttachment"), getCssValue("backgroundPosition")].join(" ");
                default: return getCssValue(cssRules);
            }
        }
    };
}());

HTMLInputElement.prototype.selection = HTMLTextAreaElement.prototype.selction = function (start, end) {
    if (start !== undefined) {
        if (!end) {
            end = this.value.length;
        }
        wkh.tools.setInputSelection(this, start, end);
    } else {
        wkh.tools.getInputSelection(this);
    }
};

Element.prototype.getClassList = (function () {
    function add(className) {//添加类
        var length = this.length;
        for (var i = 0; i < length; ++i) {
            if (this[i] === className) {
                return;
            }
        }

        this.push(className);
        this.__wkh_private_element.className = this.join(" ");
    }

    function remove(className) {//移除一个类
        var length = this.length;
        for (var i = 0; i < length; ++i) {
            if (this[i] === className) {
                for (var j = i; j < length - 1; ++j) {
                    this[j] = this[j + 1];
                }
                this.length = length - 1;
                this.__wkh_private_element.className = this.join(" ");
                return;
            }
        }
    }

    function toggle(className) {//如果没有，则添加，如果有，则删除
        var length = this.length;

        for (var i = 0; i < length; ++i) {
            if (this[i] === className) {
                for (var j = i; j < length - 1; ++j) {
                    this[j] = this[j + 1];
                }
                this.length = length - 1;
                this.__wkh_private_element.className = this.join(" ");
                return;
            }
        }

        this.push(className);
        this.__wkh_private_element.className = this.join(" ");
    }

    function contains(className) {//是否存在类
        var length = this.length;
        for (var i = 0; i < length; ++i) {
            if (this[i] === className) {
                return true;
            }
        }

        return false;
    }

    function item() {

    }

    function toString() {
        return this.join(" ");
    }

    return function () {//返回class列表对名，如果原生有classList,则返回它
        if (this.classList) {
            return this.classList;
        } else {
            var classNameList = this.className.trim().split(/[\s]+/g);
            classNameList.__wkh_private_element = this;
            classNameList.add = add;
            classNameList.remove = remove;
            classNameList.toggle = toggle;
            classNameList.contains = contains;
            classNameList.item = item;
            classNameList.toString = toString;

            this.classList = classNameList;
            return classNameList;
        }
    };
}());

if (!(document.head || document.getElementsByTagName("head")[0]).contains) {//兼容火狐浏览器的contains方法
    HTMLElement.prototype.contains = function (B) {
        return this.compareDocumentPosition(B) - 19 > 0;
    };
}

if (!(document.head || document.getElementsByTagName("head")[0]).removeNode) {//兼容removeNode方法
    HTMLElement.prototype.removeNode = function (deep) {
        if (this.parentNode) {
            if (deep === true) {
                return this.parentNode.removeChild(this);
            } else {
                var frame = document.createDocumentFragment();
                var children = this.childNodes;

                while (children.length) {
                    frame.appendChild(children[0]);
                }

                this.parentNode.insertBefore(frame, this);
                return this.parentNode.removeChild(this);
            }
        }
    };
}

Element.prototype.getContainsPath = function (other) {//返回由other到this元素的路径,路径数组为this到other元素
    var path = [other];

    if (this === other) {//如果other与this相等，直接返回path
    } else {
        try {
            while (other.parentNode !== this) {
                other = other.parentNode;
                path.unshift(other);
            }
        }
        catch (e) {
            return null;
        }
        path.unshift(this);
    }
    return path;
};

(function () {
    var eventNotPropagation = { focus: true, blur: true, mouseenter: true, mouseleave: true, load: true, readystatechange: true, error: true,input:true };//不进行事件传播的事件类型
    var ieEvent = { mouseenter: true, mouseleave: true, focusin: true, focusout: true };//对没有这些事件的浏览器进行模拟

    if (!Element.prototype.addEventListener) {//标准事件侦听器兼容性修正
        function handler(event) {//模拟事件捕获程序
            event = event || window.event;//事件对象，兼容
            var eventString = event.type;//事件类型

            if (eventString in eventNotPropagation) return;//如果事件为非传播事件，返回
            //ie8事件方法兼容性修正
            if (!event.preventDefault) {
                event.cancelable = false;
                event.bubbles = true;
                event.preventDefault = function () {
                    this.returnValue = false;
                    this.cancelable = true;
                };
                event.stopPropagation = function () {
                    this.cancelBubble = true;
                    this.bubbles = false;
                };
                event.__wkh_private_stopImmediatePropagation = false;
                event.stopImmediatePropagation = function () {
                    this.__wkh_private_stopImmediatePropagation = true;
                };
                event.target = event.srcElement;
                if (eventString === "mouseover") {
                    event.relatedTarget = event.fromElement;
                } else if (eventString === "mouseout") {
                    event.relatedTarget = event.toElement;
                } else {
                    event.relatedTarget = event.fromElement || event.toElement;
                }
            } else {
                event.__wkh_private_stopImmediatePropagation = false;
                var tempFn = event.stopImmediatePropagation;
                event.stopImmediatePropagation = function () {
                    this.__wkh_private_stopImmediatePropagation = true;
                    tempFn.call(event);
                };
            }

            var funcs = [];//注册的捕获函数列表

            var nowNode = event.target || document;//历遍事件传播路径
            var captureList, bubbleList;//元素当前事件列表
            do {
                if (!nowNode.__wkh_private_event) continue;

                if ((captureList = nowNode.__wkh_private_event.capture[eventString]) && captureList.length !== 0) {
                    funcs.unshift([nowNode, captureList]);
                }

                if ((bubbleList = nowNode.__wkh_private_event.bubble[eventString]) && bubbleList.length !== 0) {
                    funcs.push([nowNode, bubbleList]);
                }
            }
            while (nowNode = nowNode.parentNode);

            var iLength = funcs.length;
            for (var i = 0; i < iLength; ++i) {//执行
                var currentTarget = funcs[i][0];
                var eventFuncs = funcs[i][1];
                if (!event.currentTarget) {
                    event.currentTarget = currentTarget;
                }
                var jLength = eventFuncs.length;
                for (var j = 0; j < jLength; ++j) {
                    eventFuncs[j].call(currentTarget, event);
                    if (event.__wkh_private_stopImmediatePropagation) break;
                }
                if (event.cancelBubble || event.__wkh_private_stopImmediatePropagation) break;
            }

            event.cancelBubble = true;
        }

        function reviseEventHandler(fn) {//反回一个非捕获事件的修正事件
            return function (event) {
                event = event || window.event;
                var eventString = event.type;//事件类型

                if (eventString === "readystatechange" && event.srcElement.readyState === "loading") {
                    return;
                }

                //ie8事件方法兼容性修正
                if (!event.preventDefault) {
                    event.cancelable = false;
                    event.bubbles = true;
                    event.preventDefault = function () {
                        this.returnValue = false;
                        this.cancelable = true;
                    };
                    event.stopPropagation = function () {
                        this.cancelBubble = true;
                        this.bubbles = false;
                    };
                    event.__wkh_private_stopImmediatePropagation = false;
                    event.stopImmediatePropagation = function () {
                        this.__wkh_private_stopImmediatePropagation = true;
                    };
                    event.target = event.srcElement;
                    event.relatedTarget = event.fromElement || event.toElement;
                    event.currentTarget = event.target;
                    if (eventString === "mouseenter") {
                        event.relatedTarget = event.fromElement;
                    } else if (eventString === "mouseleave") {
                        event.relatedTarget = event.toElement;
                    } else {
                        event.relatedTarget = event.fromElement || event.toElement;
                    }
                }

                fn.call(event.target, event);
            };
        }

        var ieAddListener = function (eventString, eventHandler, isCapture) {

            if ((eventString === "load" && this.onload === undefined) || (eventString === "error" && this.onerror === undefined)) {
                eventString = "readystatechange";
            }

            if (!this.__wkh_private_event) {//如果没有事件列表对象，创建
                this.__wkh_private_event = {};//事件列表对象
                this.__wkh_private_event.capture = {};//捕获事件列表，不重复添加相同处理函数
                this.__wkh_private_event.bubble = {};//冒泡事件列表，不重复添加相同处理函数
                this.__wkh_private_event.notPropagation = {};//不进行传播事件列表，不重复添加相同处理函数
                this.__wkh_private_event.isRegistered = {};//是否注册程序
            }

            var notPropagationList;//不进行传播事件中当前事件类型的事件列表
            if (eventString in eventNotPropagation) {//如果该事件为不传播事件
                if (!(notPropagationList = this.__wkh_private_event.notPropagation[eventString])) {//如果不进行传播事件列表中无当前事件类型的事件列表，创建
                    notPropagationList = this.__wkh_private_event.notPropagation[eventString] = [];
                    notPropagationList.revise = [];//修正后的函数
                }

                for (var i in notPropagationList) {//如果事件处理函数已经在事件列表中，不重复添加，仅仅返回
                    if (notPropagationList[i] === eventHandler) return;
                }

                notPropagationList.push(eventHandler);//将事件函数加入事件列表中
                eventHandler = reviseEventHandler(eventHandler);
                notPropagationList.revise.push(eventHandler);
                this.attachEvent("on" + eventString, eventHandler);//用原生事件注册函数添加事件处理函数并返回
                return;
            }

            var eventList;//捕获和冒泡当前事件类型的事件列表
            var which = isCapture ? "capture" : "bubble";//事件过程

            if (!(eventList = this.__wkh_private_event[which][eventString])) {//如果事件列表中无当前事件类型的事件列表，创建
                eventList = this.__wkh_private_event[which][eventString] = [];
            }

            for (var i in eventList) {//如果事件处理函数已经在事件列表中，不重复添加，仅仅返回
                if (eventList[i] === eventHandler) return;
            }

            eventList.push(eventHandler);//将事件加入事件列表中

            if (!this.__wkh_private_event.isRegistered[eventString]) {//如果没有注册捕获事件处理函数
                this.attachEvent("on" + eventString, handler);//用原生事件注册函数添加捕获事件处理函数并返回
                this.__wkh_private_event.isRegistered[eventString] = true;
            }
            return;
        };

        var ieRemoveListener=function (eventString, eventHandler, isCapture) {
            var notPropagationList;//不进行传播事件中当前事件类型的事件列表
            if (eventString in eventNotPropagation) {//如果该事件为不传播事件
                if (!this.__wkh_private_event || !(notPropagationList = this.__wkh_private_event.notPropagation[eventString]) || notPropagationList.length === 0) {//如果不进行传播事件列表中无当前事件类型的事件列表，返回
                    return;
                }

                for (var i in notPropagationList) {//如果事件处理函数已经在事件列表中，删除事件处理函数
                    if (notPropagationList[i] === eventHandler) {
                        eventHandler = notPropagationList.revise[i];
                        this.detachEvent("on" + eventString, eventHandler);//用原生事件注册函数注销事件处理函数并返回

                        var length = notPropagationList.length;
                        for (var j = Number(i) ; j < length - 1; ++j) {
                            notPropagationList[j] = notPropagationList[j + 1];
                            notPropagationList.revise[j] = notPropagationList[j + 1];
                        }
                        notPropagationList.length = notPropagationList.revise.length = length - 1;

                        break;
                    }
                }
                return;
            }

            var eventList;
            var which = isCapture ? "capture" : "bubble";
            if (!this.__wkh_private_event || !(eventList = this.__wkh_private_event[which][eventString]) || eventList.length === 0) {//如果捕获事件列表中无当前事件类型的事件列表，返回
                return;
            }

            for (var i in eventList) {//如果事件处理函数已经在事件列表中，删除事件处理函数
                if (eventList[i] === eventHandler) {
                    var length = eventList.length;
                    for (var j = Number(i) ; j < length - 1; ++j) {
                        eventList[j] = eventList[j + 1];
                    }
                    eventList.length = length - 1;

                    if ((!(eventList = this.__wkh_private_event.capture[eventString]) || eventList.length === 0) && (!(eventList = this.__wkh_private_event.bubble[eventString]) || eventList.length === 0)) {//如果元素上没有事件，则去掉捕获事件处理程序
                        this.detachEvent("on" + eventString, handler);
                        this.__wkh_private_event.isRegistered[eventString] = false;
                    }
                    break;
                }
            }
            return;
        };

        var inputEventList = [];//input事件原函数
        var inputArgEventList = [];//input事件修正函数

        Element.prototype.addEventListener = document.addEventListener = function (eventString, eventHandler, isCapture) {
            if (eventString === "input") {
                eventString = "propertychange";
                inputEventList.push(eventHandler);
                var tempFn = eventHandler;
                eventHandler = function (e) {
                    if (e.propertyName != 'value') return;
                    else tempFn(e);
                }
                inputArgEventList.push(eventHandler);

                ieAddListener.apply(this, arguments);
            } else {
                ieAddListener.apply(this, arguments);
            }
        };

        Element.prototype.removeEventListener = document.removeEventListener = function (eventString, eventHandler, isCapture) {
            if (eventString === "input") {
                eventString = "propertychange";
                var i = inputEventList.contains(eventHandler);
                if (i!=-1) {
                    eventHandler = inputArgEventList[i];

                    inputEventList.remove(i);
                    inputArgEventList.remove(i);//移除事件

                    

                    ieRemoveListener.apply(this, arguments);
                }
            } else {
                ieRemoveListener.apply(this, arguments);
            }
        }
    } else { //修改addEventListener,用以记录事件
        /*注：在使用mouseenter和mouseleave等非传播ie事件时，使用event.target属性代替event.currentTarget，或使用this*/
        var addListener = Node.prototype.addEventListener;//原事件侦听器函数
        var removeListener = Node.prototype.removeEventListener;

        if (!("onmouseenter" in (document.head || document.getElementsByTagName("head")[0]))) {//如果没有mouseenter和mouseleave事件，在document捕获mouseover和mouseout事件模拟
            (function () {
                function handler(event) {//事件句柄
                    var relatedTarget = event.relatedTarget || document;
                    var target = event.target;
                    /*在相关节点和目标节点往上找到共同的*
                    **祖先元素，只有该节点到目标节点间的*
                    **所有节点引发这两个事件(不包括共同的*
                    **祖先节点)。*/
                    var relatedTargetElementList = [];
                    var targetElementList = [];

                    var ok = false;//是否已经完成寻找，优化

                    var nowNode = target;
                    do {//至下而上历遍目标节点之上节点
                        if (nowNode !== relatedTarget) {//优化，如果某节点为相关节点，则直接完成节点搜索
                            targetElementList.unshift(nowNode);
                        } else {
                            ok = true;
                            break;
                        }
                    } while (nowNode = nowNode.parentNode);

                    if (!ok) {//如果未完成，至下而上历遍相关节点之上节点
                        nowNode = relatedTarget;
                        do {
                            relatedTargetElementList.unshift(nowNode);
                        } while (nowNode = nowNode.parentNode);

                        while (true) {
                            if (relatedTargetElementList[0] === targetElementList[0]) {//如较，删除目标节点之上列表中，相同的元素，找出最近共同的祖先元素
                                targetElementList.shift();
                                relatedTargetElementList.shift();
                            } else {
                                ok = true;
                                break;
                            }
                        }
                    }

                    var eventFn;
                    if (event.type === "mouseover") {//运行这些节点事件名柄，两个不同事件执行顺序不同
                        for (var i in targetElementList) {
                            if (targetElementList[i].__wkh_private_event && (eventFn = targetElementList[i].__wkh_private_event.notPropagation.mouseenter) && eventFn.length !== 0) {
                                for (var j in eventFn) {
                                    eventFn[j].call(targetElementList[i], event);
                                }
                            }
                        }
                    } else {
                        for (var i = targetElementList.length - 1; i >= 0; --i) {
                            if (targetElementList[i].__wkh_private_event && (eventFn = targetElementList[i].__wkh_private_event.notPropagation.mouseleave) && eventFn.length !== 0) {
                                for (var j in eventFn) {
                                    eventFn[j].call(targetElementList[i], event);
                                }
                            }
                        }
                    }
                }

                document.addEventListener("mouseover", handler, true);
                document.addEventListener("mouseout", handler, true);
            }());
        }

        Node.prototype.addEventListener = function (eventString, eventHandler, isCapture) {
            if (typeof isCapture === "undefined") {//兼容性修正，可以忽略isCapture参数
                isCapture = false;
            }

            if (!this.__wkh_private_event) {//如果没有事件列表对象，创建
                this.__wkh_private_event = {};//事件列表对象
                this.__wkh_private_event.capture = {};//捕获事件列表，不重复添加相同处理函数
                this.__wkh_private_event.bubble = {};//冒泡事件列表，不重复添加相同处理函数
                this.__wkh_private_event.notPropagation = {};//不进行传播事件列表，不重复添加相同处理函数
                this.__wkh_private_event.isRegistered = {};//是否注册程序
            }

            var eventList;//捕获和冒泡当前事件类型的事件列表
            var which;
            if (eventString in eventNotPropagation) {
                which = "notPropagation";
            } else {
                which = isCapture ? "capture" : "bubble";//事件过程
            }

            if (!(eventList = this.__wkh_private_event[which][eventString])) {//如果事件列表中无当前事件类型的事件列表，创建
                eventList = this.__wkh_private_event[which][eventString] = [];
            }

            for (var i in eventList) {//如果事件处理函数已经在事件列表中，不重复添加，仅仅返回
                if (eventList[i] === eventHandler) return;
            }

            eventList.push(eventHandler);//将事件加入事件列表中

            if (eventString in ieEvent && !("on" + eventString in document.body)) {
            } else {
                if (eventString === "mouseenter" || eventString === "mouseleave") {//兼容性修正，mouseenter和mouseleave时第三个参数都为false
                    isCapture = false;
                }
                addListener.apply(this, arguments);
            }
        };

        Node.prototype.removeEventListener = function (eventString, eventHandler, isCapture) {
            if (typeof isCapture === "undefined") {//兼容性修正，可以忽略isCapture参数
                isCapture = false;
            }

            var eventList;
            var which;
            if (eventString in eventNotPropagation) {
                which = "notPropagation";
            } else {
                which = isCapture ? "capture" : "bubble";
            }
            if (!this.__wkh_private_event || !(eventList = this.__wkh_private_event[which][eventString]) || eventList.length === 0) {//如果捕获事件列表中无当前事件类型的事件列表，返回
                return;
            }

            for (var i in eventList) {//如果事件处理函数已经在事件列表中，删除事件处理函数
                if (eventList[i] === eventHandler) {
                    var length = eventList.length;
                    for (var j = Number(i) ; j < length - 1; ++j) {
                        eventList[j] = eventList[j + 1];
                    }
                    eventList.length = length - 1;

                    if (eventString in ieEvent && !("on" + eventString in document.body)) {
                    } else {
                        if (eventString === "mouseenter" || eventString === "mouseleave") {
                            isCapture = false;
                        }
                        removeListener.apply(this, arguments);
                    }
                    break;
                }
            }
            return;
        };
    }
}());//标准事件方法及扩展（mouseenter,mouseleave）

Element.prototype.one = window.one = document.one = function (type, handler, isCapture) {
    function tempHandler(e) {
        this.removeEventListener(type, tempHandler, isCapture);

        return handler(e);
    }
    this.addEventListener(type, tempHandler, isCapture);
};

Element.prototype.trigger = function (type) {
    if ((type === "mouseenter" || type === "mouseleave") && this.onmouseenter === undefined) {
        if (type === "mouseenter") {
            type = "mouseover";
        } else {
            type = "mouseleave";
        }
    }
    if ((type === "onload" && this.onload === undefined) || (type === "onerror" && this.onerror === undefined)) {
        type = readystatechange;
    }
    if (document.createEvent) {
        var e = document.createEvent("HTMLEvents");
        e.initEvent(type, true, true);
        this.dispatchEvent(e);
    } else {
        this.fireEvent("on" + type);
    }
};

Element.prototype.animateTo = function (to, time, onComplete, delay, progress) {//动画快捷实现，要使用动画类

    time = time || 500;

    for (var css in to) {
        var value = to[css];
        to[css] = [this.css(css), value];
    }
    var ani = new wkh.classes.Animates(this, to, time, progress);

    if (onComplete) {
        ani.addEventListener("complete", onComplete);
    }

    if (delay) {
        setTimeout(function () { ani.doAnimate(); }, delay);
    } else {
        ani.doAnimate();
    }
    //}
};

(function () {//拖动函数
    var dragElement = {};//the element need to be draged
    dragElement.proNum = 0;
    dragElement.length = 0;
    var nowDraged;

    var mousePageX, mousePageY;//the mouse point when element drag start
    var elementLeft, elementTop;

    var offsetX, offsetY;

    function mouseDownHandler(e) {
        e = e || window.event;

        if (e.type === "mousedown") {
            var target = e.target;
            var etargetDragNum;
            for (var i=0;i<dragElement.length;++i ) {
                if (dragElement[i].contains(target)) {
                    etargetDragNum = dragElement[i].__wkh_private_dragNum;
                    break;
                }
            }
            if ((etargetDragNum === undefined) || !(nowDraged = dragElement[etargetDragNum])) return;
            document.addEventListener("mouseup", mouseUpHandler, true);

            nowDraged.__wkh_private_cssText = nowDraged.style.cssText;
            nowDraged.css("userSelect", "none");
            nowDraged.addEventListener("selectstart", selectstart);//禁止选择
        } else {
            document.removeEventListener("mousemove", mouseDownHandler, true);
        }
        document.addEventListener("mousemove", moveHandler, true);

        var cssRules = nowDraged.getComputedStyle();

        var scroll = window.getScrollOffset();

        if (cssRules.position === "static") throw "元素定位为static，无法实现移动";
        else if (cssRules.position === "fixed") {
            mousePageX = e.clientX;
            mousePageY = e.clientY;
        } else {
            mousePageX = e.pageX || e.clientX + scroll.x;
            mousePageY = e.pageY || e.clientY + scroll.y;
        }
        var viewPortSize = window.getViewportSize();
        var box = nowDraged.getBoundingClientRect();

        elementLeft = parseFloat(nowDraged.css("left"));
        elementTop = parseFloat(nowDraged.css("top"));

        offsetX = elementLeft - mousePageX;
        offsetY = elementTop - mousePageY;
    }

    function moveHandler(e) {
        e = e || window.event;

        var scroll = window.getScrollOffset();
        if (nowDraged.getComputedStyle().position === "fixed") {
            mousePageX = e.clientX;
            mousePageY = e.clientY;
        } else {
            mousePageX = e.pageX || e.clientX + scroll.x;
            mousePageY = e.pageY || e.clientY + scroll.y;
        }

        nowDraged.__wkh_private_movetypeFn(mousePageX, offsetX, mousePageY, offsetY);
    }

    function moveX(x1, x2, y1, y2) {
        this.style.left = x1 + x2 + "px";
    }
    function moveY(x1,x2, y1, y2) {
        this.style.top = y1 + y2 + "px";
    }
    function moveAll(x1, x2, y1, y2) {
        this.style.left = x1 + x2 + "px";
        this.style.top = y1 + y2 + "px";
    }

    function mouseUpHandler(e) {
        document.removeEventListener("mousemove", moveHandler, true);
        document.removeEventListener("mouseup", mouseUpHandler, true);

        var left = nowDraged.css("left");
        var top = nowDraged.css("top");
        nowDraged.style.cssText = nowDraged.__wkh_private_cssText;
        nowDraged.css({
            left: left,
            top: top
        });
        nowDraged.removeEventListener("selectstart", selectstart);
    }

    function selectstart() {
        return false;
    }

    Element.prototype.startMove = function (moveType) {
        //if (this.getComputedStyle().position === "static") throw "元素定位为static，无法实现移动";
        if (!moveType) {
            moveType = "all";
        } else {
            moveType = moveType.toLowerCase();
        }
        switch (moveType) {
            case "all":
                this.__wkh_private_movetypeFn = moveAll;
                break;
            case "x":
                this.__wkh_private_movetypeFn = moveX;
                break;
            case "y":
                this.__wkh_private_movetypeFn = moveY;
                break;
            default:
                this.__wkh_private_movetypeFn = moveAll;
                break;
        }

        nowDraged = this;

        this.__wkh_private_cssText = nowDraged.style.cssText;
        this.css("userSelect", "none");
        this.addEventListener("selectstart", selectstart);//禁止选择

        document.addEventListener("mousemove", mouseDownHandler, true);

        var thisObj = this;
        document.addEventListener("click", function temp(e) {
            thisObj.stopMove();
            document.removeEventListener("click", temp, true);
        },true);
    };

    Element.prototype.stopMove = function () {
        nowDraged = null;

        var left = this.css("left");
        var top = this.css("top");
        this.style.cssText = this.__wkh_private_cssText;
        this.css({
            left: left,
            top: top
        });
        this.removeEventListener("selectstart", selectstart);

        document.removeEventListener("mousemove", moveHandler, true);
    };

    Element.prototype.drag = function (moveType) {
        if (!moveType) {
            moveType = "all";
        } else {
            moveType = moveType.toLowerCase();
        }
        switch (moveType) {
            case "all":
                this.__wkh_private_movetypeFn = moveAll;
                break;
            case "x":
                this.__wkh_private_movetypeFn = moveX;
                break;
            case "y":
                this.__wkh_private_movetypeFn = moveY;
                break;
            default:
                this.__wkh_private_movetypeFn = moveAll;
                break;
        }

        if (this.__wkh_private_dragNum === undefined) {
            this.__wkh_private_dragNum = dragElement.proNum++;
            dragElement.length++;
        }

        dragElement[this.__wkh_private_dragNum] = this;

        document.addEventListener("mousedown", mouseDownHandler, true);
    };

    Element.prototype.unDrag = function () {
        var etargetDraNum = this.__wkh_private_dragNum;
        if (etargetDraNum !== undefined) {
            delete dragElement[etargetDraNum];
            dragElement.length--;
        }

        if (nowDraged === this) {
            nowDraged = null;
        }

        if (dragElement.length === 0) {
            document.removeEventListener("mousedown", mouseDownHandler, true);
        }
    };
}());//元素拖动api


//表单验证
if (!HTMLFormElement.prototype.checkValidity) {//若没有原生表单验证
    (function () {
        HTMLSelectElement.prototype.checkValidity = HTMLInputElement.prototype.checkValidity = HTMLTextAreaElement.prototype.checkValidity = HTMLButtonElement.prototype.checkValidity = function () {
            if (this.__wkh_private_check === true) {
                return false;
            }
            var required;
            if ("required" in this) {
                required = this.required;
            } else {
                required = (this.getAttribute("required") === "required");
                this.required = required;
            }
            var value = this.value;

            this.validationMessage = "";

            switch (this.type.toLowerCase()) {
                case "submit": case "reset": case "button": case "select-one"://如果为提交，重置，按钮类型，或单选下拉单返回true
                    return true;
                    break;
                case "select-multiple"://如果为多选下拉单
                    if (required && this.selectedIndex === -1) {
                        this.validationMessage = "请在列表中选择一项";
                        return false
                    } else {
                        return true;
                    }
                    break;
                case "text": case "password": case "textarea": //如果为密码文本或文件类型
                    var pattern;
                    try {//正则表达
                        if (this.pattern) {
                            pattern = new RegExp(this.pattern);
                        } else {
                            pattern = new RegExp(this.getAttribute("pattern") || "");
                        }
                    } catch (e) {
                        pattern = new RegExp("");
                    }
                    var title = this.title || "";
                    if (required) {
                        if (value === "") {
                            this.validationMessage = "请填写此字段：" + title;
                        } else if (!pattern.test(value)) {
                            this.validationMessage = "请与所要求的格式保持一致：" + title;
                        } else {
                            return true;
                        }
                        return false;
                    } else {
                        if (value === "") {//如果为空，内正确（无required）
                            return true;
                        } else {
                            if (!pattern.test(value)) {
                                this.validationMessage = "请与所要求的格式保持一致：" + title;
                                return false;
                            } else {
                                return true;
                            }
                        }
                    }
                    break;
                case "file":
                    if (required && value === "") {
                        this.validationMessage = "请选择文件";
                        return false;
                    } else {
                        return true;
                    }
                case "checkbox":
                    if (required && (this.checked === false)) {
                        this.validationMessage = "请选择此选项";
                        return false;
                    } else {
                        return true;
                    }
                    break;
                case "radio":
                    if (required) {
                        var radioList = (this.name && this.form[this.name]) || [this];
                        var returnValue = false;
                        Array.prototype.forEachB.call(radioList, function (v) {
                            if (v.checked) {
                                returnValue = true;
                                Array.stop();
                            }
                        });
                        if (!returnValue) {
                            this.validationMessage = "请在这些选项中选择一个";
                        }
                        return returnValue;
                    } else {
                        return true;
                    }
                    break;
                default:
                    return true;
                    break;
            }
        };

        HTMLSelectElement.prototype.setCustomValidity = HTMLInputElement.prototype.setCustomValidity = HTMLTextAreaElement.prototype.setCustomValidity = HTMLButtonElement.prototype.setCustomValidity = function (errorMessage) {
            if (errorMessage === "") {
                this.__wkh_private_check = false;
            } else {
                this.__wkh_private_check === true;
            }
            this.validationMessage = errorMessage;
        };

        HTMLFormElement.prototype.checkValidity = function () {
            var returnValue = true;

            Array.prototype.forEachB.call(this, function (v) {
                if (!v.checkValidity()) {
                    returnValue = false;
                    Array.stop();
                }
            });
            return returnValue;
        };

        function setAlertCss(i){//设置错误警示样式
            i.css("outline", "2px solid red");
        }
        function setAlertShow(i) {//设置错误提示
            if (!i.__wkh_private_checkedAlertDiv) {
                i.__wkh_private_checkedAlertDiv = document.createElement("div");
            }
            var alertDiv = i.__wkh_private_checkedAlertDiv;
            alertDiv.innerText = i.validationMessage;
            var iBoxSize = i.getBoxSize();
            alertDiv.css({
                position: "absolute",
                left: iBoxSize.left + "px",
                top: iBoxSize.bottom + 5 + "px",
                padding: "5px",
                opacity: "0.8",
                border: "1px solid lightgray",
                boxShdow: "1px 1px 2px 5px gray",
                background: "white"
            });
            document.body.appendChild(alertDiv);
        }
        function clearAlertCss(i) {//去除错误警示样式
            i.css("outline", "");
        }
        function clearAlertShow(i) {//去除错误提示
            if (i.__wkh_private_checkedAlertDiv) {//若存在
                i.__wkh_private_checkedAlertDiv.removeNode(true);
            }
        }

        document.addEventListener("click", function (e) {
            var target = e.target;
            if (target.type && target.type === "submit"&&target.form) {
                var form = target.form;
                var noValidate;//是否要验证表单
                var formNoValidate;//按钮验证
                if ("formNoValidate" in target) {
                    formNoValidate = target.formNoValidate;
                } else {
                    formNoValidate = target.getAttribute("formnovalidate") === "formnovalidate";
                    target.formNoValidate = formNoValidate;
                }
                if (formNoValidate) {
                    return;
                }

                if ("noValidate" in form) {
                    noValidate = form.noValidate;
                } else {
                    noValidate = form.getAttribute("novalidate") === "novalidate";
                    form.noValidate = noValidate;
                }
                if (noValidate) {//如果不需要验证，返回
                    return;
                }

                var isListener = false;//是否已经侦听
                function prevent(e) {//阻止表单提交侦听函数
                    e.preventDefault();
                }
                var radioIsCheck = {};
                Array.prototype.forEach.call(form, function (i) {
                    if (i.type === "radio" && i.name && radioIsCheck[i.name]) {//若为单选列表，且已经校验
                        return;
                    }

                    clearTimeout(i.__wkh_private_checkedTimeout || 0);
                    clearAlertCss(i);
                    clearAlertShow(i);

                    var result = i.checkValidity();//校验结果

                    //错误处理
                    if (!result) {
                        if (i.type === "radio" && i.name) {
                            radioIsCheck[i.name] = true;
                            Array.prototype.forEach.call(i.form[i.name], function (radio) {
                                setAlertCss(radio);
                            });
                            i.__wkh_private_checkedTimeout = setTimeout(function () {
                                Array.prototype.forEach.call(i.form[i.name], function (radio) {
                                    clearAlertCss(radio);
                                });
                                clearAlertShow(i);
                            }, 5000);
                            Array.prototype.forEach.call(i.form[i.name], function (i) { 
                                i.one("focus", function () {
                                    Array.prototype.forEach.call(i.form[i.name], function (radio) {
                                        clearAlertCss(radio);
                                        clearAlertShow(radio);
                                    });
                                });
                            })
                        } else {
                            setAlertCss(i);
                            i.__wkh_private_checkedTimeout = setTimeout(function () {
                                clearAlertCss(i);
                                clearAlertShow(i);
                            }, 5000);
                            i.one("focus", function () {
                                clearAlertCss(i);
                                clearAlertShow(i);
                            });
                        }

                        setAlertShow(i);

                        if (!isListener) {//侦听事件，阻止提交
                            form.one("submit", prevent);
                            isListener = true;
                        }
                    }

                });
            }
        }, true);
    }());
}


//js内置类型功能扩充
if (!Object.create) {//模拟实现Object的create函数，不包括第二个参数
    wkh.tools.setInnerKey(Object,"create",function (proto) {
        if (proto == null) throw TypeError();
        var t = typeof proto;
        if (t !== "object" && t !== "function") throw TypeError();

        function f() { }
        f.prototype = proto;
        return new f();
    });
}


wkh.tools.setInnerKey(Object,"classof",function (o) {//获得对象的类属性
    if (o === null) return "Null";
    if (o === undefined) return "Undefined";
    return Object.prototype.toString.call(o).slice(8, -1);
});

//if (!window.jQuery) {//与jquery冲突
//    wkh.tools.setInnerKey(Object.prototype, "classof", function () {
//        return Object.classof(this);
//    });
//}

wkh.tools.setInnerKey(Math, "factorial",
    wkh.tools.memorize(function (n) {//阶乘
        return (n <= 1) ? 1 : n * Math.factorial(n - 1);
    })
);

wkh.tools.setInnerKey(Math,"permutation",function (n, m) {//排列
    if (this.isInteger(n) && this.isInteger(m)) {
        if (n >= m && m >= 0 && n > 0) {
            return this.factorial(n) / this.factorial(n - m);
        } else {
            throw new RangeError("参数取值范围不正确");
        }
    }
});

wkh.tools.setInnerKey(Math,"combination",function (n, m) {//组合
    if (this.isInteger(n) && this.isInteger(m)) {
        if (n >= m && m >= 0 && n > 0) {
            return this.factorial(n) / this.factorial(n - m) / this.factorial(m);
        } else {
            throw new RangeError("参数取值范围不正确");
        }
    }
});

wkh.tools.setInnerKey(Math,"isInteger",function (num) {//判断是否为整数

    return (/^-?\d+$/).test(num.toString().trim());
});

wkh.tools.setInnerKey(Math,"isFloat",function (num) {//判断是否为实数

    return (/^(-?\d+)(\.\d+)?$/).test(num.toString().trim());
});

wkh.tools.setInnerKey(Math,"getBeziercurve",function (pointArr) {//取得贝塞尔曲线函数
    if (Object.classof(pointArr) !== "Array") {
        throw new TypeError("参数类型不正确");
    }

    var num = pointArr.length / 2;

    if (!this.isInteger(num) || num < 2) {
        throw new RangeError("数组元素个数为偶数个且至少四个（两个点）");
    }

    return function (t) {

        if (t < 0 || t > 1) {
            throw new RangeError("参数t值在0到1内");
        }
        var x = 0,
            y = 0;//返回坐标点

        var pow = num - 1;//次方

        for (var i = 0; i < num; ++i) {
            x += pointArr[i * 2] * Math.combination(pow, i) * Math.pow(t, i) * Math.pow(1 - t, pow - i);
            y += pointArr[i * 2 + 1] * Math.combination(pow, i) * Math.pow(t, i) * Math.pow(1 - t, pow-i);
        }

        return [x, y];
    };
});

wkh.tools.setInnerKey(String.prototype, "getByteLength", function () {//取得字符串字节长度
    return this.replace(/[^\x00-\xff]/g, 'xx').length;
});


if (!Array.isArray) {//模拟isArray方法
    wkh.tools.setInnerKey(Array,"isArray",function (o) {
        return typeof o === "object" && Object.prototype.toString.call(o) === "[object Array]";
    });
}

if (!Function.prototype.bind) {//模拟bind方法
    (function () {
        wkh.tools.setInnerKey(Function.prototype, "bind", function(o) {
            var self = this, boundArgs = arguments;

            return function () {
                var args = [], i;
                for (i = 1; i < boundArgs.length; ++i) args.push(boundArgs[i]);
                for (i = 0; i < arguments.length; ++i) args.push(arguments[i]);
                return self.apply(o, args);
            };
        });
    }());
}

if (!String.prototype.trim) {//去除字符串首尾空格
    (function () {
        wkh.tools.setInnerKey(String.prototype, "trim", function() {
            if (!this) return this;//空字符串不做处理
            return this.replace(/^\s+|\s+$/g, "");
        });
    }());
}



(function () {
    wkh.tools.setInnerKey(Array.prototype, "contains", function(member) {//是否含有相应的元素
        var length = this.length;
        for (var i = 0; i < length; ++i) {
            if (this[i] === member) {
                return i;
            }
        }

        return -1;
    });
}());

(function () {
    wkh.tools.setInnerKey(Array.prototype, "remove", function(index) {//移除数组元素，返回被移除元素
        if (Object.classof(index) !== "Number") {
            return Array.prototype.remove.call(this, Array.prototype.contains.call(this, index));
        }
        var length = this.length;
        if (index < 0 || index > length) {
            return;
        }

        var returnVal = this[index];

        for (var i = index; i < length - 1; ++i) {
            this[i] = this[i + 1];
        }
        Array.prototype.pop.call(this);

        return returnVal;
    });
}());

(function () {
    wkh.tools.setInnerKey(Array.prototype, "clone", function () {//复制数组
        return Array.prototype.slice.call(this, 0);
    });
}());

(function () {
    if (!Array.prototype.forEach) {
        wkh.tools.setInnerKey(Array.prototype, "forEach", function (fn, thisObj) {//模拟forEach方法
            thisObj = thisObj || window;
            var length = this.length;
            for (var i = 0; i < length; ++i) {
                fn.call(thisObj, this[i], i, this);
            }
        });
    }

    breakError = new Error("StopIteration");
    wkh.tools.setInnerKey(Array, "stop", function () {
        throw breakError;
    });
    wkh.tools.setInnerKey(Array.prototype,"forEachB", function(fn, thisObj) {//可中途断出的forEach方法
        try {
            if (!this.forEach) {//如果没有forEach函数的类数组对象
                Array.prototype.forEach.call(this, fn, thisObj);
            } else {
                this.forEach(fn, thisObj);
            }
        } catch (e) {
            if (e === breakError) {
                return;
            } else {
                throw e;
            }
        }
    });
}());

if (!window.FormData && !wkh.tools._ie67) {
    /*
 * FormData for XMLHttpRequest 2 - Polyfill for Web Worker (c) 2012 Rob W
 * License: Creative Commons BY - http://creativecommons.org/licenses/by/3.0/
 * - append(name, value[, filename])
 * - toString: Returns an ArrayBuffer object
 *
 * Specification: http://www.w3.org/TR/XMLHttpRequest/#formdata
 * http://www.w3.org/TR/XMLHttpRequest/#the-send-method
 * The .append() implementation also accepts Uint8Array and ArrayBuffer objects
 * Web Workers do not natively support FormData:
 * http://dev.w3.org/html5/workers/#apis-available-to-workers
 **/
    (function () {
        // Export variable to the global scope
        (this == undefined ? self : this)['FormData'] = FormData;

        var ___send$rw = XMLHttpRequest.prototype.send;
        XMLHttpRequest.prototype['send'] = function (data) {
            if (data instanceof FormData) {
                if (!data.__endedMultipart) data.__append('--' + data.boundary + '--\r\n');
                data.__endedMultipart = true;
                this.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + data.boundary);
                data = new Uint8Array(data.data).buffer;
            }
            // Invoke original XHR.send
            return ___send$rw.call(this, data);
        };

        function FormData() {
            // Force a Constructor
            if (!(this instanceof FormData)) return new FormData();
            // Generate a random boundary - This must be unique with respect to the form's contents.
            this.boundary = '------WebKitFormBoundary' + Math.random().toString(36);
            var internal_data = this.data = [];
            /**
            * Internal method.
            * @param inp String | ArrayBuffer | Uint8Array Input
            */
            this.__append = function (inp) {
                var i = 0, len;
                if (typeof inp === 'string') {
                    for (len = inp.length; i < len; i++)
                        internal_data.push(inp.charCodeAt(i) & 0xff);
                } else if (inp && inp.byteLength) {/*If ArrayBuffer or typed array */
                    if (!('byteOffset' in inp)) /* If ArrayBuffer, wrap in view */
                        inp = new Uint8Array(inp);
                    for (len = inp.byteLength; i < len; i++)
                        internal_data.push(inp[i] & 0xff);
                }
            };
        }
        /**
        * @param name String Key name
        * @param value String|Blob|File|Uint8Array|ArrayBuffer Value
        * @param filename String Optional File name (when value is not a string).
        **/
        FormData.prototype['append'] = function (name, value, filename) {
            if (this.__endedMultipart) {
                // Truncate the closing boundary
                this.data.length -= this.boundary.length + 6;
                this.__endedMultipart = false;
            }
            var valueType = Object.prototype.toString.call(value),
            part = '--' + this.boundary + '\r\n' +
            'Content-Disposition: form-data; name="' + name + '"';

            if (/^\[object (?:Blob|File)(?:Constructor)?\]$/.test(valueType)) {
                return this.append(name,
                new Uint8Array(new FileReaderSync().readAsArrayBuffer(value)),
                filename || value.name);
            } else if (/^\[object (?:Uint8Array|ArrayBuffer)(?:Constructor)?\]$/.test(valueType)) {
                part += '; filename="' + (filename || 'render.png').replace(/"/g, '%22') + '"\r\n';
                part += 'Content-Type: image/png\r\n\r\n';
                this.__append(part);
                this.__append(value);
                part = '\r\n';
            } else {
                part += '\r\n\r\n' + value + '\r\n';
            }
            this.__append(part);
        };
    })();
}

//ie67兼容性
(function () {
    if (wkh.tools._ie67) {
        //for (var i in HTMLDocument.prototype) {
        //    document[i] = HTMLDocument.prototype[i];
        //}

        wkh.tools.ready(function () {
            wkh.tools._ie67();
        });
    }
}());